package com.fangyi.yunmusic.service.notification;

import com.alibaba.fastjson.JSON;
import com.fangyi.yunmusic.pojo.ws.ArtistReviewNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Service
public class ArtistReviewNotificationService {

    private Logger logger = LoggerFactory.getLogger(ArtistReviewNotificationService.class);

    public static final String ARTIST_REVIEW_NOTIFICATION = "artist-review-notification";

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void add(String userId, String artistId, Boolean allow) {
        ArtistReviewNotification artistReviewNotification = new ArtistReviewNotification();
        artistReviewNotification.setUserId(userId);
        artistReviewNotification.setArtistId(artistId);
        artistReviewNotification.setAllow(allow);
        redisTemplate.opsForValue().set(ARTIST_REVIEW_NOTIFICATION + ":" + artistReviewNotification.getUserId(), JSON.toJSONString(artistReviewNotification));
    }


    public void remove(String userId) {
        redisTemplate.delete(ARTIST_REVIEW_NOTIFICATION + ":" + userId);
    }

    public String getNotificaction(String userId) {
        return redisTemplate.opsForValue().get(ARTIST_REVIEW_NOTIFICATION + ":" + userId);
    }


}
